package com.newidea.facillty.controller;

import cn.hutool.json.JSONObject;
import com.newidea.facillty.restful.ApiResult;
import com.newidea.facillty.service.DatunService;
import com.newidea.facillty.service.HuaweiOpcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping(value = "/api/collect")
public class CollectController {

    private final DatunService datunService;
    private final HuaweiOpcService huaweiOpcService;

    public CollectController(
        DatunService datunService,
        HuaweiOpcService huaweiOpcService
    ) {
        this.datunService = datunService;
        this.huaweiOpcService = huaweiOpcService;
    }

    /**
     * 采集ModbusTCP中的数据
     */
    @PostMapping("/heatFacility")
    public ResponseEntity<ApiResult<JSONObject>> modbus() throws Exception {
        log.info("采集大屯ModbusTCP数据");
        // 采集ModbusTCP中的数据
        JSONObject collect = datunService.collect();
        return ApiResult.ok(collect);
    }
    /**
     * 采集ModbusTCP中的数据
     */
    @PostMapping("/hwOpc")
    public ResponseEntity<ApiResult<JSONObject>> hwOpc() throws Exception {
        log.info("采集华威OPC数据");
        return ApiResult.ok(huaweiOpcService.getOpcAllTag());
    }

}
